package com.google.code.gaestats;

import com.googlecode.objectify.annotation.Embed;
import lombok.Data;
import lombok.RequiredArgsConstructor;

/**
 *
 * @author JaggardM
 */
@Embed
@Data
@RequiredArgsConstructor
public class Statistics
{

	final Long max;
	final Long min;
	final Long qty;
	final Long sum;

	public Statistics merge(Statistics other)
	{
		Long newMax = (this.max == null) ? other.max : ((this.max.compareTo(other.max) > 0) ? this.max : other.max);
		Long newMin = (this.min == null) ? other.min : ((this.min.compareTo(other.min) < 0) ? this.min : other.min);
		Long newQty = (this.qty == null) ? other.qty : ((other.qty == null) ? this.qty : this.qty + other.qty);
		Long newSum = (this.sum == null) ? other.sum : ((other.sum == null) ? this.sum : this.sum + other.sum);
		return new Statistics(newMax, newMin, newQty, newSum);
	}
}
